package com.meizhao.api.filter;

import com.meizhao.api.utils.HttpUtils;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter(filterName = "securityFilter", urlPatterns = "/*", asyncSupported = true)
public class SecurityFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        SecurityHttpServletRequestWrapper xssRequest = new SecurityHttpServletRequestWrapper((HttpServletRequest) request);
        xssRequest.setAttribute("base", HttpUtils.getContextUrl(xssRequest));
        chain.doFilter(xssRequest, response);
    }

    @Override
    public void destroy() {

    }
}